#include "firewall_product_detection.h"
#include "debug.h"
#include "wmi_query.h"

const TCHAR kWmiSecurityCenter[]        = _T("root\\SecurityCenter");
const TCHAR kWmiQueryFirewallProduct[]  = _T("select * from FirewallProduct");
const TCHAR kWmiPropDisplayName[]       = _T("displayName");
const TCHAR kWmiPropVersionNumber[]     = _T("versionNumber");

namespace firewall_detection
{
	HRESULT Detect(CString* name, CString* version)
	{
		ASSERT1(name);
		ASSERT1(version);

		name->Empty();
		version->Empty();

		WmiQuery wmi_query;
		HRESULT hr = wmi_query.Connect(kWmiSecurityCenter);
		if (FAILED(hr))
			return hr;
		hr = wmi_query.Query(kWmiQueryFirewallProduct);
		if (FAILED(hr))
			return hr;
		if (wmi_query.AtEnd())
			return E_FAIL;
		hr = wmi_query.GetValue(kWmiPropDisplayName, name);
		if (FAILED(hr))
			return hr;
		
		wmi_query.GetValue(kWmiPropVersionNumber, version);
		return S_OK;
	}
}
